package com.tianjian.oa.system.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tianjian.common.Criteria;
import com.tianjian.oa.system.mapper.DepartmentMapper;
import com.tianjian.oa.system.pojos.Department;
import com.tianjian.oa.system.pojos.Tree;
import com.tianjian.util.GeneralUitl;

/**
 * @author 胡正衛
 */
@Service
public class DepartmentService {

	@Autowired
	private DepartmentMapper departmentMapper;

	public List<Department> getData(Criteria criteria) {
		try {
			return departmentMapper.getData(criteria);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int count(Criteria criteria) {
		try {
			return departmentMapper.getCount(criteria);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int insert(Department department) {
		try {
			return departmentMapper.insert(department);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	public int update(Department department) {
		try {
			return departmentMapper.update(department);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	public int delete(String bh) {
		try {
			return departmentMapper.delete(bh);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	/**
	 * 获取医院关联科室菜单树
	 */
	public List<Tree> getTree(Criteria criteria) {
		List<Tree> tree = departmentMapper.getTree(criteria);
		return GeneralUitl.Tree(tree, "id", "pid", "children");
	}

}
